#include <stdio.h>
#include <stdlib.h>  //定义了exit
#include <fcntl.h>  //定义了文件打开标识符，定义了open()
#include <unistd.h> //定义了close(), read()
#include <string.h> //定义了strlen()
#define BUF_LEN 4096

int main() {
    int srcfd;  //文件描述符
	char buf[BUF_LEN];
    int cc;

    if ((srcfd = open("test.txt", O_RDONLY)) < 0) {
		perror("test.txt");
		exit(1);
	}

    if ((cc = read(srcfd, buf, BUF_LEN)) < 0) {
		perror("read");
		exit(1);
	}
    printf("buf_len = %ld\n", strlen(buf));    //buf数组的长度为23，23B的大小
    printf("文件内容:%s\n", buf);               
    printf("cc = %d, buf_len = %d\n", cc, BUF_LEN);  //cc返回的是buf数组的长度，=23

    return 0;
}